#!/bin/sh

# TODO 24-02-09
# + do version check of yaws
# - do version check of erlyweb
#   => I don't know if this works if you have a symlink in your $ERLIB    
# - automagic installation of database schema for blogging
# - fix erlyweb and yaws check

set -e

ERLIB=$(erl -noshell -eval 'io:format(code:lib_dir()).' -s erlang halt)
YAWS=$(erl -noshell -eval 'io:format(code:lib_dir(yaws)).' -s erlang halt)
#ERLYWEB=$(erl -noshell -eval 'io:format(code:lib_dir(erlyweb)).' -s erlang halt)

if ! test -d $YAWS
then
  echo "YAWS is not installed"  
  exit 1
fi

#if ! test -d $ERLYWEB
#then
#  echo "Erlyweb is not installed"  
#  exit 1
#fi

cat >Emakefile <<EOF
{"src/*", [debug_info, {outdir, "ebin"}, {i,"$ERLIB"}]}.
{"src/components/*", [debug_info, {outdir, "ebin"}, {i,"$ERLIB"}]}.
EOF

erl -noshell -eval 'make:all(), filelib:fold_files("src/", ".+\.et$", true, fun(F, _Acc) -> erltl:compile(F, [{outdir, "ebin"}, debug_info, show_errors, show_warnings]) end, []).' -pa ebin -s erlang halt
